package edu.tamu.cs.studio;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Lab3Activity extends Activity implements OnClickListener
{
    /** Called when the activity is first created. */
	EditText	txtData;
	Button	btnWriteSDFile;
	Button	btnReadSDFile;
	Button	btnClearScreen;
	Button	btnClose;
	/**	Called	when	the	activity	is	first	created.	*/
					@Override
	public void onCreate(Bundle	savedInstanceState)	
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.text);
		 File	myFile	=	new File("/sdcard/mysdfile_easy.txt");
		 try {
			myFile.createNewFile();
		//	write_to_files(myFile);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 myFile	=	new File("/sdcard/mysdfile_medium.txt");
		 try {
			myFile.createNewFile();
			//write_to_files(myFile);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 myFile	=	new File("/sdcard/mysdfile_hard.txt");
		 try {
			myFile.createNewFile();
			//write_to_files(myFile);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//		bind	GUI	elements	with	local	controls
		 txtData =	(EditText)	findViewById(R.id.editText_text);
		 btnWriteSDFile =	(Button)	findViewById(R.id.btnWrite);
		 btnWriteSDFile.setOnClickListener(this);
	}
	public void write_to_files(File difficulty,String scoreboards) throws IOException
	{
		FileOutputStream fOut = new FileOutputStream(difficulty);
		OutputStreamWriter	myOutWriter	= new OutputStreamWriter(fOut);
		myOutWriter.append(scoreboards + " top_score\n");
		Toast.makeText(getBaseContext(),
				"Done	writing SD	"+difficulty,
				Toast.LENGTH_SHORT).show();
		myOutWriter.append("name 56\n");
		myOutWriter.close();
		fOut.close();
		Toast.makeText(getBaseContext(),
		"Done	writing SD	'mysdfile.txt'",
		Toast.LENGTH_SHORT).show();
	}
	public void read_from_file(File difficulty1)
	{
		
		//String [][]name_score = new String[5][];
		//String split[] = data.split(" ");
		//final TextView textViewToChange = (TextView) findViewById(R.id.rate);
		//textViewToChange.setText(
	}

	public void onClick(View v)
	{
		//	write	on	SD	card	file	data	in	the	text	box
		try 
		{
			// FileOutputStream fOut = new FileOutputStream(myFile);
			// OutputStreamWriter	myOutWriter	= new OutputStreamWriter(fOut);
			// myOutWriter.append(txtData.getText());
			// myOutWriter.close();
			// fOut.close();
			 Toast.makeText(getBaseContext(),
			 "Done	writing SD	'mysdfile.txt'",
			 Toast.LENGTH_SHORT).show();
		}	
		catch (Exception	e)	
		{
			 Toast.makeText(getBaseContext(),	e.getMessage(),
			 Toast.LENGTH_SHORT).show();
		}
	}//	onClick	//	btnWriteSDFile
					
	
}
